package com.sc.nft.enums.props.reward;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 奖励状态枚举
 */
@Getter
@AllArgsConstructor
public enum RewardDetailStatusEnum {

    PENDING(0, "待计入"),
    CREDITED(1, "已计入"),
    EXPIRED(2, "已失效");

    @EnumValue
    private final Integer code;
    private final String desc;

    public static RewardDetailStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (RewardDetailStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    @JsonCreator
    public static RewardDetailStatusEnum fromValue(String value) {
        if (value == null || value.isEmpty()) {
            return null; // 设定空字符串的默认行为
        }
        try {
            return RewardDetailStatusEnum.valueOf(value.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("Invalid value for RewardDetailStatusEnum: " + value);
        }
    }

    @JsonValue
    public String toValue() {
        return this.name();
    }
}
